//
//  RegisterViewController.m
//  Home Saigon
//
//  Created by Aka on 12/1/13.
//  Copyright (c) 2013 Le Zoom. All rights reserved.
//

#import "RegisterViewController.h"
#import "GUIController.h"

@interface RegisterViewController ()

@end

@implementation RegisterViewController

-(id)initWithGUI:(GUIController*)_mainGUI{
    self = [super init];
    mainGUI=_mainGUI;
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    self.view.backgroundColor=[UIColor whiteColor];
    self.title = @"Đăng Ký";
    //
    _scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    _scrollview.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height*2);
    _scrollview.scrollEnabled = NO ;
    //releas keyboard when click outsied it
    UITapGestureRecognizer *tapGest = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapGestPressed:)];
    
    [_scrollview addGestureRecognizer:tapGest];

    // Add logo Register
    UILabel *LogoRegister =[[UILabel alloc]initWithFrame:CGRectMake(15, 190, 80, 80)];
    UIImage *img = [UIImage imageNamed:@"register.png"];
    [LogoRegister setBackgroundColor:[UIColor colorWithPatternImage:img]];
    [_scrollview addSubview:LogoRegister];
    //Add Label Header
    UILabel *Header = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
    Header.backgroundColor = [UIColor orangeColor];
    Header.text=@"Tattoo Boutique VN";
    Header.textColor= [UIColor whiteColor];
    Header.font =[UIFont fontWithName:@"Tahoma" size:30];
    Header.textAlignment = NSTextAlignmentCenter;
    [_scrollview addSubview:Header];
    
    //Add Text Fields
    _AccountField = [[UITextField alloc]initWithFrame:CGRectMake(100, 180, 180, 30)];
    _AccountField.borderStyle = UITextBorderStyleBezel;
    _AccountField.placeholder =@"username";
    _AccountField.delegate =self;
    [_scrollview addSubview:_AccountField];
    
    _PasswordField = [[UITextField alloc]initWithFrame:CGRectMake(100, 220, 180, 30)];
    _PasswordField.borderStyle = UITextBorderStyleBezel;
    _PasswordField.placeholder = @"password";
    _PasswordField.delegate=self;
    [_scrollview addSubview:_PasswordField];
    
    _RePasswordField = [[UITextField alloc]initWithFrame:CGRectMake(100, 260, 180, 30)];
    _RePasswordField.borderStyle = UITextBorderStyleBezel;
    _RePasswordField.placeholder = @"retype password";
    _RePasswordField.delegate=self;
    [_scrollview addSubview:_RePasswordField];
    //Add Button
    UIButton *Register = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    Register.frame = CGRectMake(50, 300, 100, 30);
    [Register setTitle:@"Register" forState:UIControlStateNormal];
    Register.tag = 1;
    [_scrollview addSubview:Register];
    [Register addTarget:self action:@selector(btnpressed:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *Reset = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    Reset.frame = CGRectMake(170, 300, 100, 30);
    [Reset setTitle:@"Reset" forState:UIControlStateNormal];
    [_scrollview addSubview:Reset];
    [Reset addTarget:self action:@selector(Reset:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_scrollview];
}
-(void)tapGestPressed:(id)sender{
    [_AccountField resignFirstResponder];
    [_PasswordField resignFirstResponder];
    [_RePasswordField resignFirstResponder];
    [_scrollview setContentOffset:CGPointMake(0, 0) animated:YES];
    
}
-(void)btnpressed:(id)sender{
    [mainGUI ScreenFinish:self withCode:((UIButton*)sender).tag];
}
-(void)textFieldDidBeginEditing:(UITextField *)textField{
    [_scrollview setContentOffset:CGPointMake(0, 130) animated:YES];
    
}
-(void)Reset:(id)sender
{
    NSLog(@"Reset Clicked");
    _AccountField.text=@"";
    _PasswordField.text=@"";
    _RePasswordField.text=@"";
    
}
-(NSString*)getUsername{
    return _AccountField.text;
}
-(NSString*)getPassword{
    return _PasswordField.text;
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
